﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DeviceManager.DataAccessLayer;
using DeviceManager.BusinessLogicLayer;

namespace DeviceManagementIT.StatisticalReports.ListOfVouchers
{
    public partial class frmInventory : DevExpress.XtraEditors.XtraForm
    {
        public frmInventory()
        {
            InitializeComponent();
        }
        KIEMKE m_kiemke;
        InventoryBllOperation devicebll = new InventoryBllOperation();
        CTKiemKeBllOperation m_ctkiemkebll = new CTKiemKeBllOperation();
        private void Inventory_Load(object sender, EventArgs e)
        {
            txtNgay.Text = DateTime.Now.ToShortDateString();
            txtngayvanban.Text = DateTime.Now.ToShortDateString();

            DonviDbOperation m_UnitDbOperation = new DonviDbOperation();
            cbbdvkiemke.Properties.DataSource = m_UnitDbOperation.GetRecord(new DONVI());
            cbbdvkiemke.Properties.DisplayMember = "TenDonVi";
            cbbdvkiemke.Properties.ValueMember = "DonViID";

            GTThietBiDbOperation m_CountryDbOperation = new GTThietBiDbOperation();
            txtMatb.Properties.DataSource = m_CountryDbOperation.GetRecord(new GTTHIETBI());
            txtMatb.Properties.DisplayMember = "MaCaBiet";
            txtMatb.Properties.ValueMember = "GTThietBiID";

            TinhTrangDbOperation m_TinhTrangDbOperation = new TinhTrangDbOperation();
            cbbtinhtrang.Properties.DataSource = m_TinhTrangDbOperation.GetRecord(new TINHTRANG());
            cbbtinhtrang.Properties.DisplayMember = "TenTinhTrang";
            cbbtinhtrang.Properties.ValueMember = "TinhTrangID";
        }

        private void cbbdvkiemke_EditValueChanged(object sender, EventArgs e)
        {
            BophanDbOperation m_CountryDbOperation = new BophanDbOperation();
            BOPHAN m_bophan = new BOPHAN();
            m_bophan.BoPhanID = int.Parse(cbbdvkiemke.EditValue.ToString());
            comboBoxEdit7.Properties.DataSource = m_CountryDbOperation.GetRecord(m_bophan);
            comboBoxEdit7.Properties.DisplayMember = "TenBoPhan";
            comboBoxEdit7.Properties.ValueMember = "BoPhanID";
        }

        private void simpleButton7_Click(object sender, EventArgs e)
        {
            GTThietBiDbOperation m_CountryDbOperation = new GTThietBiDbOperation();
            txtMatb.Properties.DataSource = m_CountryDbOperation.GetRecord(new GTTHIETBI());
            txtMatb.Properties.DisplayMember = "GTThietBi";
            txtMatb.Properties.ValueMember = "GTThietBi";
        }

        private void simpleButton10_Click(object sender, EventArgs e)
        {

        }

        private void btnThemKiemKe_Click(object sender, EventArgs e)
        {
            InventoryDbOperation m_inventory = new InventoryDbOperation();
            CTKiemKeBllOperation unitbll = new CTKiemKeBllOperation();
            CTKIEMKE m_ctkiemke = new CTKIEMKE();

            m_ctkiemke.KiemKeID = m_kiemke.KiemKeID;
            m_ctkiemke.GTThietBiID = int.Parse(txtMatb.EditValue.ToString());
            m_ctkiemke.TinhTrang1 = int.Parse(cbbtinhtrang.EditValue.ToString());
            m_ctkiemke.HienTrang1 = mmhientrang.EditValue.ToString();
            m_ctkiemke.TinhTrang0 = int.Parse(cbbtinhtrang.EditValue.ToString());
            m_ctkiemke.HienTrang0 = mmhientrang.EditValue.ToString();

            string message1 = m_ctkiemkebll.SaveRecordDevice(m_ctkiemke);
            MessageBox.Show(message1, "Message");

            CTKIEMKE m_ctkiemke1 = new CTKIEMKE();
            m_ctkiemke1.KiemKeID = m_kiemke.KiemKeID;
            List<CTKIEMKE> listunit = unitbll.GetRecordDevice(m_ctkiemke1);
            gridControlKiemke.DataSource = listunit;
            gridViewkiemke.Columns[1].Caption = "Thông tin kiểm kê";
            gridViewkiemke.Columns[2].Caption = "Mã vạch kiểm kê";
            gridViewkiemke.Columns[0].Visible = false;
            gridViewkiemke.Columns[4].Visible = false;
            gridViewkiemke.Columns[5].Visible = false;
        }
        private void txtMatb_EditValueChanged(object sender, EventArgs e)
        {
            DeviceDbOperation m_UnitDbOperation = new DeviceDbOperation();
            THIETBI m_thietbi = new THIETBI();
            m_thietbi.ThietBiID = int.Parse(txtMatb.EditValue.ToString());
            txttenthietbi.Properties.DataSource = m_UnitDbOperation.GetRecord(m_thietbi);
            txttenthietbi.Properties.DisplayMember = "TenThietBi";
            txttenthietbi.Properties.ValueMember = "ThietBiID";
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            m_kiemke = new KIEMKE();

            m_kiemke.NgayKiemKe = DateTime.Parse(txtNgay.EditValue.ToString());
            m_kiemke.NgayVanBan = DateTime.Parse(txtngayvanban.EditValue.ToString());
            m_kiemke.SoVanBan = cbbsovanban.EditValue.ToString();
            m_kiemke.ThamQuyenQD = txtthamquyenqd.EditValue.ToString();
            m_kiemke.GhiChu = mmcghichu.EditValue.ToString();
            m_kiemke.BoPhanKiemKe = int.Parse(comboBoxEdit7.EditValue.ToString());
            m_kiemke.DonViKiemKe = int.Parse(cbbdvkiemke.EditValue.ToString());

            string message = devicebll.SaveRecordDevice(m_kiemke);
            MessageBox.Show(message, "Message");
        }
    }
}